package algorithm_study.leecode;

class strStr {
    public static int strStr(String haystack, String needle) {
        char[] hchar = haystack.toCharArray();
        char[] nchar = needle.toCharArray();
        int count =0;
        int count1=0;
        int count3=0;
        for(int i=0;i<hchar.length;++i){
            if(hchar[i]==nchar[count1]){
                ++count1;
                if(hchar[i]==nchar[0])count3=i-1;
            }
            else {
                count1=0;
                i=Math.max(count3,count++) ;
            }
            if(count1==(nchar.length))break;
        }
        if(count1==nchar.length)return count;
        else return -1;
    }

    public static void main(String[] args) {
        System.out.println(strStr("mississippi","issip"));
    }
}
